def is_simple(x):
    for d in range(2, int(x**(0.5))+1):
        if x%d == 0: return False
    return True
def spr(): 
    sp = []
    for i in range(101,998):
        if is_simple(i):
            sp.append(i)
    return sp


Alfa = {
    'zero':'0', 'one':'1', 'two':'2', 'three':'3', 'four':'4', 'five':'5', 'six':'6', 'seven':'7','eight':'8', 'nine':'9'
    }
s = input()
sw = s.split()
p =''
for g in sw:
    p +=Alfa[g]
if(len(p)!=3):
    print('Wrong input')
else:
    a = max(x for x in spr()if x<=int(p))
    b = min(x for x in spr()if x>=int(p))
    if abs(int(p)-a) > abs(int(p)-b):
        print(b)
    else:print(a)
